package com.orange.common.web.config;

import com.orange.common.web.interceptor.TraceIDInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description:springMvc配置类
 * 使用自动装配，纳入spring容器管理
 */
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {
    /**
     * @Description:注入拦截器对象
     */
    @Autowired
    private TraceIDInterceptor traceIDInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns 用于添加拦截规则, 这里假设拦截 /url 后面的全部链接
        // excludePathPatterns 用户排除拦截
        registry.addInterceptor(traceIDInterceptor).addPathPatterns("/**");
    }
}
